package com.zhuojy.equity.mall.admin.web.controller.salary;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhuojy.equity.mall.admin.common.entity.bo.salary.AddPeopleBO;
import com.zhuojy.equity.mall.admin.common.entity.bo.salary.TUserArchivesBO;
import com.zhuojy.equity.mall.admin.common.entity.po.salary.TUserArchivesPO;
import com.zhuojy.equity.mall.admin.common.entity.vo.salary.TUserArchivesVO;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.common.utils.ExcelUtils;
import com.zhuojy.equity.mall.admin.service.salary.TUserArchivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**

/**
 * @description: 员工薪资档案模块
 * @author chen
 * @date 2024/4/11 18:50
 * @version 1.0
 */
@RestController
@RequestMapping("archive")
@RequiredArgsConstructor
@Api(tags = "薪资模块")
public class TUserArchivesController {

    private final TUserArchivesService tUserArchivesService;

    @PostMapping("getUserArchiveList")
    @ApiOperation(value = "获取员工薪资档案列表",httpMethod = "POST",notes = "获取员工薪资档案列表")
    public ResultEntity getUserArchiveList(@RequestBody TUserArchivesBO tUserArchivesBO){
        try {
            Map map  = tUserArchivesService.getUserArchiveList(tUserArchivesBO);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("获取薪资档案列表失败");
        }
    }

    @GetMapping("exprotPoi")
    @ApiOperation(value = "导出员工薪资档案列表",httpMethod = "GET",notes = "导出员工薪资档案列表")
    public void exprotPoi(HttpServletResponse response){
        try {
            List<TUserArchivesVO> list = tUserArchivesService.exprotPoi();
            ExcelUtils.export(response,"员工薪资档案.xlsx",list,TUserArchivesVO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @GetMapping("findEmployeePayrollFilesInfo")
    @ApiOperation(value = "查看员工薪资档案详情",httpMethod = "GET",notes = "查看员工薪资档案详情")
    public ResultEntity findEmployeePayrollFilesInfo(@RequestParam("id") Long id){
        try {
            TUserArchivesPO one = tUserArchivesService.getOne(Wrappers.lambdaQuery(TUserArchivesPO.class).eq(TUserArchivesPO::getId, id));
            return ResultEntity.OK(one);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查看员工薪资档案详情失败!!!");
        }
    }

}
